package property.service.impl;

import org.apache.ibatis.session.SqlSession;
import property.mapper.FeedbackDisposeMapper;
import property.pojo.FeedbackDispose;
import property.pojo.FeedbackDisposeKey;
import property.service.FeedbackDisposeService;
import property.utils.mapper.MyBatisUtil;

public class FeedbackDisposeServiceImpl implements FeedbackDisposeService {
    @Override
    public int addFeedbackDispose(FeedbackDispose feedbackDispose) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        FeedbackDisposeMapper mapper = sqlSession.getMapper(FeedbackDisposeMapper.class);
        int i = 0;
        try {
             i = mapper.insertSelective(feedbackDispose);
        }catch (Exception e){
            if (e.getMessage().toString().contains("PRIMARY") || e.getMessage().toString().contains("FOREIGN KEY")) {
                i = -2;
            }
        }
        sqlSession.commit();
        sqlSession.close();
        return i;
    }

    @Override
    public int deleteFeedbackDispose(FeedbackDisposeKey feedbackDisposeKey) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        FeedbackDisposeMapper mapper = sqlSession.getMapper(FeedbackDisposeMapper.class);
        int i = mapper.deleteByPrimaryKey(feedbackDisposeKey);
        sqlSession.commit();
        sqlSession.close();
        return i;
    }

    @Override
    public int updateFeedbackDispose(FeedbackDispose feedbackDispose) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        FeedbackDisposeMapper mapper = sqlSession.getMapper(FeedbackDisposeMapper.class);
        int i = mapper.updateByPrimaryKeySelective(feedbackDispose);
        sqlSession.commit();
        sqlSession.close();
        return i;
    }
}
